﻿using DevExpress.XtraEditors;
using MesProjectWinform.Public.Common;
using MesProjectWinform.Public.Output;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MesProjectWinform.Public.Form
{
    public partial class DocCodeForm : DevExpress.XtraEditors.XtraForm
    {
        public DocCodeForm()
        {
            InitializeComponent();
        }

        private async void DocCodeForm_Load(object sender, EventArgs e)
        {
            var response = await HttpClientHelper.RequestUrl(RequestType.Get, MethodGolab.GetDocCode, null);
            ApiResult<List<DocOutput>> result = JsonConvert.DeserializeObject<ApiResult<List<DocOutput>>>(response);
            if (result != null && result.Data != null && result.Data.Count > 0)
            {
                gridControl1.DataSource = result.Data;
                gridView1.BestFitColumns(); // 自动调整列宽
            }
            else
            {
                XtraMessageBox.Show("没有获取到单据编码数据！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            AddDocForm addDocForm = new AddDocForm();
            //addDocForm.MyEvent += (s, args) => DocCodeForm_Load(null, null); // 订阅事件
            addDocForm.MyDelegateCallback = () => DocCodeForm_Load(null, null); // 赋值委托
            addDocForm.ShowDialog(); // 弹出添加单据编码的窗口
        }
    }
}